<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="ttp://www.security.com/tag" prefix="sc"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="1"> 
<script src="js/alai_tree/alai_tree.js"></script>
<script src="js/alai_tree/alai_tree_pretty.js"></script>
<script src="js/alai_tree/alai_tree_check.js"></script>
<script src="js/prototype-1.4.0.js"></script>
<script src="js/InputTool.js"></script>
<script src='js/comm.js'></script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="template/css.css" rel="stylesheet" type="text/css">
<title>departmentTree</title>
</head>

<body>
<table width="100%" height="100%" border="0">
	<tr>
		<td width="20%" background="images/treebg.gif" valign="top" bordercolor="#7d7be3">
			<table><tr>
				<td class="title">过滤条件：</td>
				<td colspan="10">
					<input class="input130" id="selectFun" style="width: 70" name="selectFun" />
					<input class="searchbtn" type="button" value="搜索" onclick="search()" />
					<!-- 
					<select name="selectFun" onchange="fireFun()" >
						<option value="detail" >查看部门</option>
						<sc:component processcode="department_add"><option value="add">添加部门</option></sc:component>
						<option selected value="member">查看成员</option>
						<sc:component processcode="department_edit"><option value="edit">编辑部门</option></sc:component>
						<option value="fresh">刷新部门树</option>
					</select>
					 -->
				</td>
			</tr></table>
			<div  id="divTree1" style="overflow: auto;width: 200;height: 300;float: none;"></div>
		</td>
		<td width="80%" bordercolor="#b4fef4">
			<iframe width="100%" src="blank.jsp" frameborder="0" height="100%" name="departmentworkPlace" src=""></iframe>
		</td>
	</tr>
</table>
</body>
</html>
<script>

var tree1=new alai_tree_pretty(divTree1)
var root=tree1.root


function validateSelTree(){
	var treeNode=tree1.getSelectedNode();
	if(!treeNode){
		alert("请选择一个部门");
		return false;
	}
	return true;
}

function fireFun(){
	showMember();
}

function loadTreeNode(pidNode){
		var pid="-2";
		if(pidNode.body)pid=pidNode.body.pid
		var url="<%=request.getContextPath()%>/departmenttreenode.action?pid="+pid;
		var myAjax = new Ajax.Request(
					url, 
					{ 
						method: 'get', 
						asynchronous:false
				}); 
		var myXML = myAjax.transport.responseXML;
		addNodeToTree(myXML,pidNode);
	}
	
	function addNodeToTree(doc,pidNode){
		var nodes=doc.selectNodes("TREENODES/TREENODE");
		if(nodes.length>0){
			var node,treeNode;
			for(var i=0;i<nodes.length;i++){
				node=nodes[i];
				treeNode=pidNode.add(node.getAttribute('name'));
				treeNode.expand(false);
				treeNode.body.flg=0;
				treeNode.body.pid=node.getAttribute('id')
				treeNode.icon.src='js/alai_tree/images/fold_close.gif'
			}
		}
	}
	
function treeClkListener(){
	tree1.onclick=function(treeNode){
		var flg=treeNode.body.flg;
		if(0==flg){
			loadTreeNode(treeNode);
			treeNode.body.flg=1;
			treeNode.expand();
		}
		treeNode.expand();
		if(treeNode.expanded)treeNode.icon.src='js/alai_tree/images/fold_open.gif'
		showMember(true)
	}
}
treeClkListener()
function showMember(flg){
	var treeNode=tree1.getSelectedNode();
	var departmentid;
	try{
		departmentid=treeNode.body.pid
	}catch(e){}
	var pars="rtPage=fyList&";
	if(flg)
		pars+="departmentId="+departmentid;
	pars+="&cname="+encodeURIComponent(document.all.selectFun.value);
	//alert(pars);
	document.all.departmentworkPlace.src="userlistList.action?"+pars;
}

function search(){
	 var keyv=document.all.selectFun.value;
	 if(keyv){
	 	showMember(false);
	 }
}


loadTreeNode(root);
function freshTree(){
	divTree1.innerHTML='';
	tree1=new alai_tree_pretty(divTree1)
	root=tree1.root
	loadTreeNode(root);
	treeClkListener();
}
</script>

		
